{
  Copyright 2012 Sergey Ostanin

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
}

unit ProfileViewer;

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  Shape, Profile, ItImport, base64, VisualUtils, MiscUtils;

type
  TProfileViewerFrame = class(TShapeFrame)
    gbxProfile: TGroupBox;
    lblProfile: TLabel;
  private
    FRendered: Boolean;
    { private declarations }
  public
    procedure Render;
    { public declarations }
  end;

implementation

{$R *.lfm}

{ TProfileViewerFrame }

procedure TProfileViewerFrame.Render;
var
  Profile: TProfile;
  sl: TStringList;
  s: String;
begin
  if UpdateShape or not FRendered then
  begin
    LockRedraw(Self);
    try
      Profile := BytesToProfile(DecodeStringBase64(Shape.S['itStream']));
      try
        gbxProfile.Caption := Profile.Title;
        sl := TStringList.Create;
        try
          Profile.GetDescription(sl);
          s := sl.Text;
          lblProfile.Caption := Copy(s, 1, Length(s) - Length(LineEnding));
        finally
          sl.Free;
        end;
      finally
        Profile.Free;
      end;
    finally
      UnlockRedraw(Self);
    end;
  end;

  FRendered := TRUE;
end;

end.

